## Pseudo-code for building the diff-in-diff dataset
import json
import csv

execfile("./Dropbox/Coalitions/loadCommitteeData.py")
execfile("./Dropbox/Coalitions/cueingFunctions.py")

# Get cosponsorship data
cosponsorship = {}
with open("./Dropbox/Coalitions/cosponsorship.json", 'r') as dataf:
    cosponsorship = json.load(dataf)
    
def trust(cs, partyA, partyB):
    if cs >= 10:
        return 1
    elif partyA != partyB and cs >= 5:
        return 1
    return 0

with open("./Dropbox/Coalitions/cueing_data1616weighted.csv", 'r') as f:
    with open("./Dropbox/Coalitions/interference105.csv", 'w') as outf:
        responsereader = csv.reader(f, delimiter = ',', quotechar = '"')
        responsewriter = csv.writer(outf, delimiter = ',', quotechar = '"')
        responsewriter.writerow(responsereader.next() + ['Acuetaker', 'Bcuetaker'])
        cuegiver = ''
        cuegiver_party = ''
        for row in responsereader:
            contress = int(row[6])
            treat = int(row[4])
            if treat:
                cuegiver = row[15]
                cuegiver_party = resolveParty(cuegiver, congress, party)
                cosponsors = cosponsorship[cuegiver]
                continue
            legA = row[15]
            legB = row[16]
            partyA = resolveParty(legA, congress, party)
            partyB = resolveParty(legB, congress, party)
            legAcs = countCs(cosponsors, legA, congress)
            legBcs = countCs(cosponsors, legB, congress)
            legAtrust = str(trust(legAcs, cuegiver_party, partyA))
            legBtrust = str(trust(legBcs, cuegiver_party, partyB))
            row.append(legAtrust)
            row.append(legBtrust)
            responsewriter.writerow(row)